<template>
	
	<view class="mainpadding2" v-if="pageShow">
		<u-navbar title="核銷記錄" placeholder autoBack>
			<view class="flexright" slot="right" @click="messageTime.timeShow=true">
				<u-icon name="calendar" color="#FFB800" size="24"></u-icon>
			</view>
		</u-navbar>
		<view class="mainpadding hei_text main_size bold" v-if="start_time || end_time">{{start_time}}{{end_time?'-'+end_time:""}}</view>
		<view class="mainpadding ffffff radius" style="padding: 30rpx 160rpx;">
			<view class="flexcenter titletext bold flexbetween" style="color: #FF5C00;">
				<text>合計：{{list.total}}張</text>
				<text style="font-size: 34rpx;">${{allprice}}</text>
			</view>
		</view>
		<view class="flexcenter" v-if="!list.data.length">
			<view class="placeholderimage" style="margin-top: 100rpx;" ></view>
		</view>
		<view class="mainpadding_top ffffff radius" v-for="item in list.data" :key="item.id">
			<view class="flexbetween xiahuaxian">
				<view class="main_size hei_text ">{{item.name}}</view>
				<view class="xiaohuang bold main_size">已核銷</view>
			</view>
			<view class="flexbetween">
				<view class="titletext hei_text bold margin_top2">{{item.updatetiem_text}}</view>
				<view class="main_size flexright huang_text ">$
				<text style="font-size: 50rpx;">{{item.dk_money}}</text>
				</view>
			</view>
		</view>
		<timePicker :messageTime="messageTime" @timeConfirm="timeConfirm"></timePicker>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				page: 1,
				limit: 12,
				list: {
					data: []
				},
				messageTime: {
					mode: "date",
					timeShow: false,
					title: "請選擇開始時間"
				},
				start_time:"",
				end_time:"",
				pageShow:false,
				allprice:""
			}
		},
		onLoad() {
			this.start_time = this.http.returnDate(Number(new Date()))
			this.end_time = this.http.returnDate(Number(new Date()))
			this.init()
		},
		methods: {
			timeConfirm(e) {
				console.log(e,"999");
				if(this.messageTime.title == "請選擇開始時間"){
					this.start_time = e
					setTimeout(()=>{
						this.messageTime.title  = "請選擇結束時間"
						this.messageTime.timeShow = true
					},100)
				}else{
					this.messageTime.title = "請選擇開始時間"
					this.end_time = e
					this.init()
				}
				
			},
			init(isPage, page) {
				let _this = this;
				let data = {
					page: page || 1,
					limit: _this.limit,
					shop_id: uni.getStorageSync("shop_id"),
					start_time:this.start_time,
					end_time: this.end_time,
				}
				let url = '/api/user/shopUseRall'
				uni.showLoading({
					mask:true,
					title:"請稍後"
				})
				httpRequest.request(url, 'GET', data, false, false, true).then(res => {
					uni.hideLoading()
					if (res.code == 1) {
						let resList = res.data.data;
						let dataList = _this.list;
						if (isPage == true) {
							_this.list.data = dataList.data.concat(resList.data);
						} else {
							this.allprice = res.data.total_price
							this.list = res.data.data
							_this.list.data = resList.data;
						}
						this.pageShow = true
					}
				})
			},
			onReachBottom() {
				let _this = this;
				let list = _this.list;
				let page = _this.page;
				if (list.last_page <= page) {
					return false;
				}
				page++;
				_this.page = page;
				_this.init(true, page);
			},
		}
	}
</script>

<style>

</style>
